<?php

/**
 * Event form.
 *
 * @package    embeddForm
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class EventForm extends BaseEventForm {

    public function configure() {
        $this->embedRelation('Occurrences');
    }

     public function addNewFields($number) {
        $new_occurrences = new BaseForm();

        for ($i = 0; $i <= $number; $i+=1) {
            $occurrence = new Occurrence();
            $occurrence->setEvent($this->getObject());
            $occurrence_form = new OccurrenceForm($occurrence);

            $new_occurrences->embedForm($i, $occurrence_form);
        }

        $this->embedForm('new', $new_occurrences);
    }

    public function bind(array $taintedValues = null, array $taintedFiles = null) {

        $new_occurrences = new BaseForm();
        foreach ($taintedValues['new'] as $key => $new_occurrence) {
            $occurrence = new Occurrence();
            $occurrence->setEvent($this->getObject());
            $occurrence_form = new OccurrenceForm($occurrence);

            $new_occurrences->embedForm($key, $occurrence_form);
        }

        $this->embedForm('new', $new_occurrences);

        parent::bind($taintedValues, $taintedFiles);
    }

}
